package org.ruanjj.designmodel.proxymodel;


import java.lang.reflect.Proxy;

public class Main {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException {
        UserService target = new UserServiceImpl();
        UserService proxy = (UserService) Proxy.newProxyInstance(
                target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),
                new LogHandler(target)
        );
        proxy.save(); // 输出日志并调用目标方法
        proxy.query();

       //CGLiB
     /*   Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(User.class);
        enhancer.setCallback(new LogInterceptor());
        User proxy = (User) enhancer.create();
        proxy.createUser();*/

        // ByteBuddy等效实现
    }
}
